#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

const int N = 3e3 + 10;

typedef pair<int, int> PII;

vector<PII> edges[N * 2];

int n, m, s;
int T;
int dist[N];

bool bf()
{
	memset(dist, 0x3f, sizeof dist);
	bool flag = false;
	dist[1] = 0;
	for(int cnt = 1; cnt <= n; cnt++)
	{
		flag = false;
		for(int i = 1; i <= n; i++)
		{
			for(auto x : edges[i])
			{
				int b = x.first, c = x.second;
				if(dist[i] + c < dist[b])
				{
					flag = true;
					dist[b] = dist[i] + c;
				}
			}
		}
		if(!flag) break;
	}
	return flag;
}

int main()
{
	cin >> T;
	while(T--)
	{
		for(int i = 1; i <= n; i++) edges[i].clear();
		cin >> n >> m;
		for(int i = 1; i <= m; i++)
		{
			int u, v, w; cin >> u >> v >> w;
			edges[u].push_back({v, w});
			if(w >= 0)
			{
				edges[v].push_back({u, w});
			}
		}
		if(bf()) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

